package com.china08.yxyapi.api.manage.tec.teaching.resource.myresource;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.yxyresource.YxyResourceService;

/**
 * 老师 我的资源 修改资源
 * 
 */
@CrossOrigin
@RestController
public class ResourceIsFavorController extends YxyApiBaseController {

    @Autowired
    private YxyResourceService yrs;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/resource/isfavor/{id}", method = RequestMethod.GET)
    public Object isfavor(HttpServletRequest request, HttpServletResponse response,
            @PathVariable(value = "id") String id) {
        RespModel model = new RespModel();

        String userId = getProfile(request, response).getId();
        String schoolId = getProfile(request, response).getSchoolId();
        if (StringUtils.isNotBlank(userId)) {
            // String role = getProfile(request, response).getRoleId();
            // if (StringUtils.equalsIgnoreCase(role, "ROLE_TEACHER")) {
            long isCheck = yrs.checkFavor(userId, schoolId, "ROLE_TEACHER", id);
            model.isFavor = isCheck > 0 ? 1 : 0;
            // }
        }
        return model;
    }

    protected static class RespModel extends YxyApiRespModel {
        public Integer isFavor;
    }

}
